package com.eagleyng.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class StringUtils {

	/**
	 * md5
	 * @param inbuf
	 * @return
	 */
	public static final String md5(String inbuf) {
		if(inbuf == null || inbuf.length() == 0){
			return null;
		}
		try {
			MessageDigest dg = MessageDigest.getInstance("MD5");
			byte[] result = dg.digest(inbuf.getBytes());
			StringBuilder sb = new StringBuilder();
			for (byte bit : result) {
				sb.append(String.format("%02x",bit));
			}
			return sb.toString();
		} catch (NoSuchAlgorithmException e) {
			return null;
		}
	}
}
